//
//  UserModels.swift
//  甜言蜜语
//
//  Created by 王剑伟 on 16/6/15.
//  Copyright © 2016年 wl. All rights reserved.
//

import Foundation
import SwiftyJSON

class UserHeadModel: NSObject, NSCoding {
    
    var id: Int
    var phone: String
    var name: String
    var timg: String
    var isMe: Bool
    var isguanzhu: Bool
    var guanzhunum: Int
    var fensinum: Int
    var backimg: String
    var signature: String
    
    init(json: JSON) {
        id = json["id"].intValue
        phone = json["phone"].stringValue
        name = json["name"].stringValue
        timg = json["timg"].stringValue
        isMe = json["isme"].boolValue
        isguanzhu = json["isguanzhu"].boolValue
        guanzhunum = json["guanzhunum"].intValue
        fensinum = json["fensinum"].intValue
        backimg = json["backimg"].stringValue
        signature = json["signature"].stringValue
    }
    required init?(coder decoder: NSCoder) {
        id = decoder.decodeObjectForKey("id") as! Int
        phone = decoder.decodeObjectForKey("phone") as! String
        name = decoder.decodeObjectForKey("name") as! String
        timg = decoder.decodeObjectForKey("src") as! String
        isMe = decoder.decodeObjectForKey("isMe") as! Bool
        isguanzhu = decoder.decodeObjectForKey("isguanzhu") as! Bool
        guanzhunum = decoder.decodeObjectForKey("guanzhunum") as! Int
        fensinum = decoder.decodeObjectForKey("fensinum") as! Int
        backimg = decoder.decodeObjectForKey("backimg") as! String
        signature = decoder.decodeObjectForKey("signature") as! String
    }
    
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(id, forKey: "id")
        aCoder.encodeObject(phone, forKey: "phone")
        aCoder.encodeObject(name, forKey: "name")
        aCoder.encodeObject(timg, forKey: "timg")
        aCoder.encodeObject(isMe, forKey: "isMe")
        aCoder.encodeObject(isguanzhu, forKey: "isguanzhu")
        aCoder.encodeObject(guanzhunum, forKey: "guanzhunum")
        aCoder.encodeObject(fensinum, forKey: "fensinum")
        aCoder.encodeObject(backimg, forKey: "backimg")
        aCoder.encodeObject(signature, forKey: "signature")
    }
}

class UserHomeModel: NSObject, NSCoding {
    
    var userHeadModel: UserHeadModel
    var commentList: [CommentModel] = []
    
    init(json: JSON) {
        userHeadModel = UserHeadModel(json: json)
        let infocommentlist = json["infocommentlist"]
        for (_, dict) in infocommentlist {
            commentList.append(CommentModel(json: dict))
        }
    }
    required init?(coder decoder: NSCoder) {
        userHeadModel = decoder.decodeObjectForKey("userHeadModel") as! UserHeadModel
        commentList = decoder.decodeObjectForKey("commentList") as! [CommentModel]
    }
    
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(userHeadModel, forKey: "userHeadModel")
        aCoder.encodeObject(commentList, forKey: "commentList")
    }
}

class CommentModel: NSObject, NSCoding
{
    var id: String
    var name: String
    var message: String
    var suppose: String
    var timg: String
    var commentTime: String
    var userID: Int
    var isdianzan: Bool
    var newsInfo: NewsModel
    
    init(json: JSON) {
        id = json["id"].stringValue
        name = json["name"].stringValue
        message = json["message"].stringValue
        suppose = json["suppose"].stringValue
        timg = json["timg"].stringValue
        commentTime = json["commenttime"].stringValue
        userID = json["user"].intValue
        isdianzan = json["isdianzan"].boolValue
        newsInfo = NewsModel(json: json["infomation"])
    }
    
    required init?(coder decoder: NSCoder) {
        id = decoder.decodeObjectForKey("id") as! String
        name = decoder.decodeObjectForKey("name") as! String
        message = decoder.decodeObjectForKey("message") as! String
        suppose = decoder.decodeObjectForKey("suppose") as! String
        timg = decoder.decodeObjectForKey("timg") as! String
        commentTime = decoder.decodeObjectForKey("commentTime") as! String
        userID = decoder.decodeObjectForKey("userID") as! Int
        isdianzan = decoder.decodeObjectForKey("isdianzan") as! Bool
        newsInfo = decoder.decodeObjectForKey("newsInfo") as! NewsModel
    }
    
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(id, forKey: "id")
        aCoder.encodeObject(name, forKey: "name")
        aCoder.encodeObject(message, forKey: "message")
        aCoder.encodeObject(suppose, forKey: "suppose")
        aCoder.encodeObject(timg, forKey: "timg")
        aCoder.encodeObject(commentTime, forKey: "commentTime")
        aCoder.encodeObject(userID, forKey: "userID")
        aCoder.encodeObject(isdianzan, forKey: "isdianzan")
        aCoder.encodeObject(newsInfo, forKey: "newsInfo")
    }
}
class UserdzList: NewsModelInitProtocol{
    var id: String
    var timg: String
    var name : String
    required init(json: JSON) {
       id = json["id"].stringValue
        timg = json["timg"].stringValue
        name = json["name"].stringValue
        
    }
}
//回复页的数据
class allReplyInfo: NewsModelInitProtocol{
    var id: String
    var commentid: String
    var userdzList: [UserdzList]
    var message: String
    var userAddress: String
    var isdianzan: Bool
    var replycomment: String
    var childnum: String
    var suppose: String
    var floor: String
    var timg: String
    var user: String
    var name: String
    var commenttime: String
    var isme: Bool
    var infocomments: [NewsDetailHotReplyModel]?
    var actcomments: [NewsDetailHotReplyModel]?
    required init(json: JSON) {
        id = json["id"].stringValue
        commentid = json["commentid"].stringValue
        userdzList = ModelArrayProvider.arrayModel(UserdzList.self, json: json["userdzList"])!
        message = json["message"].stringValue
        userAddress = json["userAddress"].stringValue
        isdianzan = json["isdianzan"].boolValue
        replycomment = json["replycomment"].stringValue
        childnum = json["childnum"].stringValue
        suppose = json["suppose"].stringValue
        floor = json["floor"].stringValue
        timg = json["timg"].stringValue
        user = json["user"].stringValue
        name = json["name"].stringValue
        commenttime = json["commenttime"].stringValue
        isme = json["isme"].boolValue
        infocomments = ModelArrayProvider.arrayModel(NewsDetailHotReplyModel.self, json: json["infocomments"])
        actcomments = ModelArrayProvider.arrayModel(NewsDetailHotReplyModel.self, json: json["actcomments"])
      
        
    }
}